﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Windows.Forms;
using AutoMapper;
using TRACv2.Domain.Services;
using TRACv2.Persistence;
using TRACv2.UI.Facade;

namespace TRACv2.UI
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            CreateTypeMaps();
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new FormMain(new TRACFacade(new TicketService(new TicketRepository()), new EmployeeService(new EmployeeRepository()))));
        }

        private static void CreateTypeMaps()
        {
            Mapper.CreateMap<Persistence.Ticket, Domain.DTO.TicketDTO>();
            Mapper.CreateMap<Domain.DTO.TicketDTO, Persistence.Ticket>();
            Mapper.CreateMap<Domain.Entities.Ticket, Domain.DTO.TicketDTO>();
            Mapper.CreateMap<Domain.DTO.TicketDTO, Domain.Entities.Ticket>();
            Mapper.CreateMap<Persistence.Employee, Domain.DTO.EmployeeDTO>().
                ForMember(x => x.FirstName, y => y.MapFrom(z => z.Person.FirstName)).
                ForMember(x => x.LastName, y => y.MapFrom(z => z.Person.LastName)).
                ForMember(x => x.Department, y => y.MapFrom(z => z.Position.Department.Name));
            Mapper.CreateMap<Domain.DTO.EmployeeDTO, Persistence.Employee>().
                ForSourceMember(x => x.FirstName, y => y.Ignore()).
                ForSourceMember(x => x.LastName, y => y.Ignore()).
                ForSourceMember(x => x.Department, y => y.Ignore());
            Mapper.CreateMap<Domain.Entities.Employee, Domain.DTO.EmployeeDTO>();
            Mapper.CreateMap<Domain.DTO.EmployeeDTO, Domain.Entities.Employee>();
        }
    }
}
